using System;
using System.Collections.Generic;
using System.Data;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;
using MultiChoiceVoting.Models;

namespace MultiChoiceVoting
{
    public class Migrations : DataMigrationImpl
    {
        public int Create()
        {
            SchemaBuilder.CreateTable("MultiChoiceVotingPartRecord", table => table
                .ContentPartRecord()
                .Column<string>("Name")
                .Column<string>("Question")
                .Column<string>("AnswerList")
                .Column<string>("Comment")
                .Column<DateTime>("ReleaseDate")
                .Column<DateTime>("FinishDate")
                .Column<bool>("IsActive")
                .Column<string>("SerializedAnswers", column => column.Unlimited())
            );

            ContentDefinitionManager.AlterPartDefinition(typeof(MultiChoiceVotingPart).Name,
                builder => builder
                    .Attachable());

            ContentDefinitionManager.AlterTypeDefinition("MultiChoiceVotingWidget",
                cfg => cfg
                    .WithPart(typeof(MultiChoiceVotingPart).Name)
                    .WithPart("WidgetPart")
                    .WithPart("CommonPart")
                    .WithSetting("Stereotype", "Widget")
            );

            return 1;
        }
    }
}